package com.leetcode.algorithm.y22.m06;

/**
 * 1491. 去掉最低工资和最高工资后的工资平均值
 * 
 * https://leetcode.cn/problems/average-salary-excluding-the-minimum-and-maximum-salary/
 * 
 * @author jie.deng
 *
 */
class Question1491Solution01 {
	
	public double average(int[] salary) {
		int sum = salary[0];
		int max = salary[0];
		int min = salary[0];
		for (int i = 1; i < salary.length; i++) {
			sum += salary[i];
			if (salary[i] > max) {
				max = salary[i];
			}
			if (salary[i] < min) {
				min = salary[i];
			}
		}
		return (double) (sum - max - min) / (salary.length - 2);
	}
    
}